<?php
require_once dirname(__FILE__) . '/../config/config.php';
class GameTagController
{
    private $smarty;
    public function __construct()
    {
    }

    public function main(&$smarty)
    {
        $this->smarty = $smarty;
    }

    public function listAction()
    {
        $context = new BaseContext();
        $result = new ServiceResult();
        $gameTagService = new GameTagService();
        $gameNameArr = $gameTagService ->getFullGameTag($context, $result);
        if(isset($_POST) && !empty($_POST))
        {
        	$filter = $_POST['filter'];
        	if(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filter')
        	{
        		$gameTagArr = $gameTagService ->getFullGameTagByName($context, $result, $filter);
        	}
        }
        else 
        {
        	$gameTagArr = $gameTagService -> getFullGameTagTPG($context, $result) ;
        }
       	$this->smarty->assign('gameNameArr', $gameNameArr);
        $this->smarty->assign('gameTagArr', $gameTagArr);
        $this->smarty->display('list-game-tag.tpl');
    }

    public function addAction()
    {
        $_SESSION['timeout'] = time();
        $context = new BaseContext();
        $result = new ServiceResult();
		$gameTagService = new GameTagService();
        
        if(isset($_POST) && !empty($_POST))
        {       
            $param = $_POST;
            $gameTagService->insertGameTag($context, $result, $param);
            header("location:".WEB_BASE_URL."/index.php?controller=gameTag&action=list");
        }
        else
        {
        	$this->smarty->display('add-game-tag.tpl');
        }
    }

    public function updateAction()
    {
        $_SESSION['timeout'] = time();
    	if(isset($_GET['id']) && !empty($_GET['id']))
		{
		  	$id = $_GET['id'];
		}
        $context = new BaseContext();
        $result = new ServiceResult();
        $gameTagService = new GameTagService();
        
        $gameTag = $gameTagService ->getGameTagByID($context, $result,$id);
      
        if(isset($_POST) && !empty($_POST))
        {
            $_POST['id'] = $_POST['id'];
            $param = $_POST;
            $gameTagService->updateGameTag($context, $result, $param);

            header("location:".WEB_BASE_URL."/index.php?controller=gameTag&action=list");
        }
        $this->smarty->assign('gameTag', $gameTag);
     	$this->smarty->display('update-game-tag.tpl');
    }

}

?>